import 'package:intl/intl.dart';

class TimeHelper {
  //统一时间格式
  static String dateTimeFmt(DateTime dateTime) {
    DateFormat formatter = DateFormat("yyyy-MM-dd HH:mm:ss");
    return formatter.format(dateTime);
  }

  //统一时间格式
  static String strTimeFmt(String time) {
    DateTime dateTime = DateTime.parse(time);
    DateFormat formatter = DateFormat("yyyy-MM-dd HH:mm:ss");
    return formatter.format(dateTime);
  }

  //统一日期格式
  static String strDateFmt(String time) {
    DateTime dateTime = DateTime.parse(time);
    DateFormat formatter = DateFormat("yyyy-MM-dd");
    return formatter.format(dateTime);
  }

  //时间戳转时间格式
  static String timestampFmt(int timestampS) {
    final dateTime = DateTime.fromMillisecondsSinceEpoch(timestampS * 1000);
    final formatter = DateFormat('yyyy-MM-dd HH:mm:ss');
    return formatter.format(dateTime);
  }

  static String formatSeconds(int seconds) {
    final duration = Duration(seconds: seconds);
    final hours = duration.inHours.toString().padLeft(2, '0');
    final minutes = (duration.inMinutes % 60).toString().padLeft(2, '0');
    final secs = (duration.inSeconds % 60).toString().padLeft(2, '0');
    return '$hours:$minutes:$secs';
  }

  //获取当前时间戳
  static int currTimestampS() {
    return (DateTime.now().millisecondsSinceEpoch / 1000).toInt();
  }
}
